package com.fafa.pos.util.newland;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;

public class SharedPreferencesUtils {
	private static String TAG = "SharedPreferencesUtils";
	private static final String FILENAME = "system_setting";
	private static Context context;

	public static void setContext(Context context) {
		SharedPreferencesUtils.context = context;
	}

	/**
	 * 根据名称保存参数
	 * 
	 * @param name
	 * @param value
	 * @return
	 */
	public static boolean saveByName(String name, String value) {
		boolean reslt = false;
		try {
			SharedPreferences sp = context.getSharedPreferences(FILENAME,
					Context.MODE_PRIVATE);
			Editor editor = sp.edit();
			editor.putString(name,value);
			editor.commit();
			reslt = true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return reslt;
	}

	/**
	 * 根据名称加载参数
	 * 
	 * @param name
	 * @param defaultvalue
	 * @return
	 */
	public static String loadByName(String name, String defaultvalue) {
		try {
			SharedPreferences sp = context.getSharedPreferences(FILENAME,
					Context.MODE_PRIVATE);
			String resltString = sp.getString(name, defaultvalue);
			return resltString;
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}

	}
}
